// pages/detail/index.js
Page({
  data: {
    bookId: '',
    book: {}
  },

  onLoad(options) {
    const id = options.id;
    const book = this.getBookById(id);

    this.setData({
      bookId: id,
      book
    });
  },

  goToReader() {
    const { bookId } = this.data;
    wx.navigateTo({
      url: `/pages/reader/index?id=${bookId}`
    });
  },

  downloadPDF() {
    const { book } = this.data;
    if (book && book.pdfUrl) {
      wx.setClipboardData({
        data: book.pdfUrl,
        success() {
          wx.showModal({
            title: '下载提示',
            content: 'PDF链接已复制到剪贴板，请在浏览器中粘贴并下载文件。',
            showCancel: false,
            confirmText: '知道了'
          });
        },
        fail() {
          wx.showToast({
            title: '复制链接失败',
            icon: 'none'
          });
        }
      });
    } else {
      wx.showToast({
        title: '无效的PDF链接',
        icon: 'none'
      });
    }
  },

  getBookById(id) {
    const books = [
      {
        id: 'book1',
        title: '第一个吻',
        cover: '/images/coloring.png',
        description: '一个温暖感人的分离焦虑故事，讲述小猴子和妈妈的亲密拥抱。',
        pdfUrl: 'https://english-pdf-share-n-1320222167.cos.ap-beijing.myqcloud.com/Alphabet%20A-Z%20Worksheets%20Coloring%20and%20Tracing%20English%20Created%20Resources_compressed.pdf'
      },
      {
        id: 'book2',
        title: '我不想离开你',
        cover: '/images/copy_right.png',
        description: '袋鼠妈妈用安全的袋子来安抚小袋鼠，让孩子学会面对分离。',
        pdfUrl: 'https://english-pdf-share-n-1320222167.cos.ap-beijing.myqcloud.com/Alphabet%20Coloring%20Book%20English%20Created%20Resources_compressed.pdf'
      },
      {
        id: 'book3',
        title: '魔法亲亲',
        cover: '/images/tracing.png',
        description: '一只小浣熊要独自上学，妈妈告诉他“魔法亲亲”的秘密。',
        pdfUrl: 'https://english-pdf-share-n-1320222167.cos.ap-beijing.myqcloud.com/Alphabet%20Coloring%20and%20Tracing%20Activity%20Book%20Copyright%202022%20English%20Created%20Resources_compressed.pdf'
      },
      {
        id: 'book4',
        title: '国王爸爸',
        cover: '/images/tracing.png',
        description: '国王爸爸。',
        pdfUrl: 'https://english-pdf-share-n-1320222167.cos.ap-beijing.myqcloud.com/Alphabet%20Coloring%20and%20Tracing%20Activity%20Book%20Copyright%202022%20English%20Created%20Resources_compressed.pdf'
      },
      {
        id: 'book5',
        title: '我爸爸',
        cover: '/images/tracing.png',
        description: '我爸爸。',
        pdfUrl: 'https://english-pdf-share-n-1320222167.cos.ap-beijing.myqcloud.com/Alphabet%20Coloring%20and%20Tracing%20Activity%20Book%20Copyright%202022%20English%20Created%20Resources_compressed.pdf'
      },
      {
        id: 'book4',
        title: '爸爸带我看宇宙',
        cover: '/images/tracing.png',
        description: '爸爸带我看宇宙。',
        pdfUrl: 'https://english-pdf-share-n-1320222167.cos.ap-beijing.myqcloud.com/Alphabet%20Coloring%20and%20Tracing%20Activity%20Book%20Copyright%202022%20English%20Created%20Resources_compressed.pdf'
      
      }
      // 你可以继续添加更多绘本
    ];

    return books.find(item => item.id === id) || {};
  }
});
